package com.hzlj.position.dbsync.shanxi.config;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;

import java.util.Map;
import java.util.Objects;


public abstract class DataSourceContext {

    public void dsSwitch(Map<String, Object> params) {
        dsSwitch("master",params);
    }

    public void dsSwitch(String ds, Map<String, Object> params) {
        if (ObjectUtil.isEmpty(ds)) {
            ds = "master";
        }
        DynamicDataSourceContextHolder.push(ds);
        if (Objects.isNull(params)) {
            return;
        }
        config(ds, params);
    }

    public void clear() {
        DynamicDataSourceContextHolder.clear();
    }

    public abstract void config(String ds, Map<String, Object> params);

}